package com.szxy.item.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.szxy.item.service.ItemParamItemService;
import com.szxy.mapper.TbItemParamItemMapper;
import com.szxy.pojo.TbItemParamItem;
import com.szxy.pojo.TbItemParamItemExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Auther:zwer
 * @Date:2019/9/7 20:17
 * @Description:com.szxy.item.service.impl
 * @Version:1.0
 **/
@Service
public class ItemParamItemServiceImpl implements ItemParamItemService {

    @Autowired
    private TbItemParamItemMapper itemParamItemMapper;

    @Override
    @LcnTransaction
    public Integer insertItemParamItem(TbItemParamItem itemParamItem) {
        return this.itemParamItemMapper.insert(itemParamItem);
    }

    @Override
    public TbItemParamItem findItemParamItemByItemId(Long itemId) {
        TbItemParamItemExample example = new TbItemParamItemExample();
        TbItemParamItemExample.Criteria criteria = example.createCriteria();
        criteria.andItemIdEqualTo(itemId);
        List<TbItemParamItem> itemParamItemList =
                this.itemParamItemMapper.selectByExampleWithBLOBs(example);
        if(itemParamItemList !=null && itemParamItemList.size() > 0){
            return itemParamItemList.get(0);
        }
        return null;
    }

    @Override
    @LcnTransaction
    public int updateItemParamItemByItemId(TbItemParamItem itemParamItem) {
        itemParamItem.setUpdated(new Date());
        TbItemParamItemExample example = new TbItemParamItemExample();
        TbItemParamItemExample.Criteria criteria = example.createCriteria();
        criteria.andItemIdEqualTo(itemParamItem.getItemId());
        return this.itemParamItemMapper.updateByExampleSelective(itemParamItem,example);
    }
}
